Skip to main content
This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal

HCL Notes/Domino 8.5 Forum (includes Notes Traveler)

HCL Notes/Domino 8.5 Forum (includes Notes Traveler)

Previous Next

use UIInput.isValid and FacesContext.getMessages

The information is available using the JSF APIs.
The component corresponding to an edit box is a javax.faces.UIInput
(same applies to a combo box or any other field that inputs a field value).
During the validation, if the field is not valid, UIInput.isValid will be set to false.

Also during validation, FacesMessage objects are added to the facesContext
for each control that fails validation. If the control has multiple validators that fail,
then multiple messages will be added.

For example:
Paste this source into an XPage and Preview. If you click the submit button without entering a value
in the edit box, then the computed fields will display the error messages.
Hide details for Example sourceExample source
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
A required field:<xp:br></xp:br>
<xp:inputText id="inputText1" value="#{requestScope.something}"
required="true" disableClientSideValidation="true">
<xp:this.validators>
<xp:validateRequired message="The field is required."></xp:validateRequired>
</xp:this.validators>
</xp:inputText>
<xp:br></xp:br>

<xp:button value="Submit" id="button1">
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete" immediate="false" save="true"></xp:eventHandler>
</xp:button>
<xp:br></xp:br>
<xp:br></xp:br>

The messages associated with inputText1:
<xp:br></xp:br>
<xp:text escape="false" id="computedField1">
<xp:this.value><![CDATA[#{javascript:
var input:javax.faces.component.UIInput = getComponent('inputText1');
if( input.isValid() ){
// no message
return "";
}
var clientId = input.getClientId(facesContext);

// the messages for that input
var messagesIter:Iterator = facesContext.getMessages(clientId);

var result = "";
while( messagesIter.hasNext() ){
var messageObj:javax.faces.application.FacesMessage
= messagesIter.next();
result += messageObj.getSummary()+ "<br/>";
}
return result;}]]></xp:this.value>
</xp:text>
<xp:br></xp:br>
<xp:br></xp:br>
All messages:
<xp:br></xp:br><xp:text escape="false" id="computedField2">
<xp:this.value><![CDATA[#{javascript:
// all messages
var messagesIter:Iterator = facesContext.getMessages();

var result = "";
while( messagesIter.hasNext() ){
var messageObj:javax.faces.application.FacesMessage
= messagesIter.next();
result += messageObj.getSummary() + "<br/>";
}
return result;}]]></xp:this.value>
</xp:text>
</xp:view>


Hope that helps.


Feedback response number MKEE7NWDPW created by ~Lex Feztookonyikle on 02/03/2009

How can I determine if an error occ... (~Tony Opresaste... 1.Feb.09)
. . use UIInput.isValid and FacesContex... (~Elizabeth Cisb... 3.Feb.09)
. . . . That's what I was looking for (~Tony Opresaste... 4.Feb.09)
. . . . Thank You! (~Wei Minluflar 22.Oct.13)




Printer-friendly

Search this forum

Member Tools


RSS Feeds

 RSS feedsRSS
All forum posts RSS
All main topics RSS